
/**
 * memblock_setclr_flag - set or clear flag for a memory region
 * @type: memblock type to set/clear flag for
 * @base: base address of the region
 * @size: size of the region
 * @set: set or clear the flag
 * @flag: the flag to update
 *
 * This function isolates region [@base, @base + @size), and sets/clears flag
 *
 * Return: 0 on success, -errno on failure.
 */
static int __init_memblock memblock_setclr_flag(struct memblock_type *type,
                                                phys_addr_t base, phys_addr_t size, int set, int flag)
{
    int i, ret, start_rgn, end_rgn;

    ret = memblock_isolate_range(type, base, size, &start_rgn, &end_rgn);
    if (ret)
        return ret;

    for (i = start_rgn; i < end_rgn; i++)
    {
        struct memblock_region *r = &type->regions[i];

        if (set)
            r->flags |= flag;
        else
            r->flags &= ~flag;
    }

    memblock_merge_regions(type, start_rgn, end_rgn);
    return 0;
}
